<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<%@ page import="com.zhouchao.util.DbUtil,com.zhouchao.dao.StudentDao"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<SCRIPT type="text/javascript">
        var req;
        window.onload=function(){
        }
       
        function check_dept()
        {
            var zhi=document.getElementById('dept').value;
            var url="change?id="+escape(zhi);
            if(window.XMLHttpRequest)
            {
                req=new XMLHttpRequest();
            }else if(window.ActiveXObject)
            {
                req=new ActiveXObject("Microsoft.XMLHTTP");
            }
           
            if(req)
            {
                req.open("POST",url,true);
                req.onreadystatechange=callback;
                req.send(null);
            }
        }
       
        function callback()
        {
            if(req.readyState == 4)
            {
                if(req.status == 200)
                {
                    parseMessage();
                }else{
                    alert("Not able to retrieve escription"+req.statusText);
                }
            }
        }
       
        function parseMessage()
        {
            var xmlDoc=req.responseXML.documentElement;
            var xSel=xmlDoc.getElementsByTagName('select');
            var select_root=document.getElementById('left_select');
            select_root.options.length=0;
           
            for(var i=0;i<xSel.length;i++)
            {
                var xValue=xSel[i].childNodes[0].firstChild.nodeValue;
                var xText=xSel[i].childNodes[1].firstChild.nodeValue;
                var option=new Option(xText,xValue);
                try{
                    select_root.add(option);
                }catch(e){
                }
            }
           
           
        }
        
        function check_dept1()
        {
            var zhi1=document.getElementById('dept1').value;
            var url="change?id="+escape(zhi1);
            if(window.XMLHttpRequest)
            {
                req=new XMLHttpRequest();
            }else if(window.ActiveXObject)
            {
                req=new ActiveXObject("Microsoft.XMLHTTP");
            }
           
            if(req)
            {
                req.open("POST",url,true);
                req.onreadystatechange=callback1;
                req.send(null);
            }
        }
       
        function callback1()
        {
            if(req.readyState == 4)
            {
                if(req.status == 200)
                {
                    parseMessage1();
                }else{
                    alert("Not able to retrieve escription"+req.statusText);
                }
            }
        }
       
        function parseMessage1()
        {
            var xmlDoc=req.responseXML.documentElement;
            var xSel=xmlDoc.getElementsByTagName('select');
            var select_root=document.getElementById('right_select');
            select_root.options.length=0;
           
            for(var i=0;i<xSel.length;i++)
            {
                var xValue=xSel[i].childNodes[0].firstChild.nodeValue;
                var xText=xSel[i].childNodes[1].firstChild.nodeValue;
                var option=new Option(xText,xValue);
                try{
                    select_root.add(option);
                }catch(e){
                }
            }
           
           
        }
        
    </SCRIPT>
<script type="text/javascript">

$(document).ready(function(){
	$("ul li:eq(4)").addClass("active");
	
});


function ltor()
{
    var os=new Array();
    os=document.getElementById("left_select").options;
     os1=document.getElementById("right_select").options;
     if(os1.length>7){
    alert("房间已满");
    }else{
    for(i=0;i<os.length;i++){
   
        if(os[i].selected){
            var o=new Option(os[i].text,os[i].value);
            document.getElementById("right_select").add(o);
            document.getElementById("left_select").remove(i);
            i--;
    }
        }
    }
}
function rtol()
{
    var os=new Array();
    os=document.getElementById("right_select").options;
    os1=document.getElementById("left_select").options;
     if(os1.length>7){
    alert("房间已满");
    }else{
    for(i=0;i<os.length;i++){
   
        if(os[i].selected){
            var o=new Option(os[i].text,os[i].value);
            document.getElementById("left_select").add(o);
            document.getElementById("right_select").remove(i);
            i--;
            }
        }
    }
}

function rtolall()
{
    var os=new Array();
    os=document.getElementById("right_select").options;
    os1=document.getElementById("left_select").options;
     if((os1.length+os.length)>7){
    alert("房间已满");
    
    }else{for(i=0;i<os.length;){
    
        var o=new Option(os[i].text,os[i].value);
        document.getElementById("left_select").add(o);
        document.getElementById("right_select").remove(i);
    }
    }
}
function ltorall()
{
//
    var os=new Array();
    os=document.getElementById("left_select").options;
    os1=document.getElementById("left_select").options;
     if((os1.length+os.length)>7){
    alert("房间已满");
   
    }else{ for(i=0;i<os.length;){
    
        var o=new Option(os[i].text,os[i].value);
        document.getElementById("right_select").add(o);
        document.getElementById("left_select").remove(i);
    }
    }
}




var v;
function queDing(){
	var os=new Array();
	os=document.getElementById("left_select").options;
	os1=document.getElementById("right_select").options;
	var left=document.getElementById("dept").value;
	var right=document.getElementById("dept1").value;
	var v="";
	var v1="";
	for(var i=0;i<os.length;i++){
		v+=os[i].value+",";
	}
for(var i=0;i<os1.length;i++){
		v1+=os1[i].value+",";
	}
	//opener.document.forms[0].text.value=v;
	alert("寝室调换成功");
	window.location="change?action=change&left="+left+"&right="+right+"&v="+v+"&v1="+v1;
	//this.close();
}
</script>

<script language="javascript" type="text/javascript">
 
</script>

<div class="data_list">
		<div class="data_list_title">
			寝室调换
		




<br>
    <table cellspacing="1" width="350px" align="center" border="0">
        <tr>
        
        
        <td  bgcolor="#FFFFFF">
        <select name ="s1" id="dept"  onchange="check_dept()">
            <option selected="selected">选择寝室</option>
            <c:forEach  varStatus="i" var="dorm" items="${dormlist}">
					 <option value="${dorm.dormName}">${dormBuildName} ${dorm.dormName}</option>
				</c:forEach>
				
        </select></td>
        <% %>
        
        
        <td></td>
        <td><select id="dept1"  onchange="check_dept1()">
        
        
            <option selected="selected">选择寝室</option>
            
           <c:forEach  varStatus="i" var="dorm" items="${dormlist}">
					
					 <option value="${dorm.dormName}">${dormBuildName}-${dorm.dormName}</option>
					
					
				</c:forEach>
            
            
            
        </select></td>
        </tr>
        
         <tr>
                <td>
                
                <select multiple="multiple" size="15" id="left_select" style="width : 500px" >
              
          
                </select></td>
                <td align="center">
                <input type="button" value="> " style="width:35px" onclick="ltor()"><br>
                <input type="button" value=">> " style="width:35px" onclick="ltorall()"><br>
                <input type="button" value="< " style="width:35px" onclick="rtol()"><br>
                <input type="button" value="<< " style="width:35px" onclick="rtolall()"><br>
                </td>
                <td><select multiple="multiple" style="width : 500px" size="15" id="right_select"></select></td>
            </tr>
        <tr></tr>
        
        <tr><td></td><td align="center"><input class="btn btn-large btn-primary" type="button" value="确定" onclick="queDing()"></td><td></td></tr>
        <tr>
        
        
       </table>
		</div>
		<div id='result'></div>
		<div align="center"><font color="red">${error }</font></div>
</div>